package user.mapper;

import org.apache.ibatis.annotations.*;
import user.dto.UserDto;
import user.params.TypeUpdateDto;

import java.util.List;

public interface UserMapper  {
    @Select("SELECT * FROM users ")
    public List<UserDto> selectAllUsers();

    @Insert("INSERT INTO users (username, password, email, created_at, height, weight, age, sex, protein, energy, fats, carbohydrate) " +
            "VALUES (#{username}, #{password}, #{email}, #{createdAt}, #{height}, #{weight}, #{age}, #{sex}, #{protein}, #{energy}, #{fats}, #{carbohydrate})")
    @Options(useGeneratedKeys = true) // 确保此处的keyProperty与UserDto类的属性一致
    void insertUser(UserDto user);

    @Select("SELECT * FROM users WHERE username = #{username} AND password = #{password}")
    public UserDto SelectUserByNameAndPassword(String username, String password);

    @Select("SELECT * FROM users WHERE username = #{username}")
    public UserDto SelectUserByName(String username);

    @Update("UPDATE users SET password = #{password} WHERE username = #{username}")
    public void updateUserPassword(String username, String password);


    @Select("SELECT * FROM users WHERE username = #{username}")
    public UserDto selectUserByUsername(String username);

    @Update("UPDATE users SET height = #{height}, weight = #{weight}, age = #{age}, protein = #{protein}, energy = #{energy}, fats = #{fats}, carbohydrate = #{carbohydrate} WHERE username = #{username}")
    public void updateUser(UserDto user);

    @Select("SELECT type FROM users WHERE user_id = #{userId}")
    public String getUserType(int userId);

    @Update("UPDATE users SET type = #{type} WHERE user_id = #{id}")
    public void updateUserOfType(TypeUpdateDto typeUpdateDto);

    @Select("SELECT * FROM users WHERE user_id = #{userId}")
    public UserDto selectUserById(int userId);

    @Delete("DELETE FROM users WHERE user_id = #{userId}")
    public void delUser(int userId);

    @Update("UPDATE users SET AICount = #{AICount} WHERE user_id = #{userId}")
    public void updateAICount(int userId, int AICount);
}
